package com.gin.supermarket_inventory_system.inventory.dto.vo;

import com.gin.database.base.BaseVo;
import com.gin.supermarket_inventory_system.inventory.entity.InventoryReceiptPo;
import com.gin.supermarket_inventory_system.inventory.enums.InventoryReceiptType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @since : 2023/10/12 16:26
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "视图对象:库存单据")
public class InventoryReceiptVo extends BaseVo {
    @Schema(description = "单据类型")
    InventoryReceiptType type;

    @Schema(description = "供应商ID")
    Long purveyorId;

    @Schema(description = "总价")
    double totalPrice;

    @Schema(description = "备注")
    String remark;

    @Schema(description = "操作人用户ID")
    long userId;

    @Schema(description = "供应商名称(填充)")
    String purveyorName;

    @Schema(description = "操作人名称(填充)")
    String username;

    @Schema(description = "单据详情(填充)")
    List<InventoryReceiptDetailVo> details;

    public InventoryReceiptVo(InventoryReceiptPo po) {
        // 复制Po的字段
        BeanUtils.copyProperties(po, this);
    }

    /**
     * 将持久对象列表转换为视图对象列表
     * @param data 持久对象列表
     * @return 视图对象列表
     */
    public static List<InventoryReceiptVo> toVoList(List<InventoryReceiptPo> data) {
        if (data == null) {
            return new ArrayList<>();
        }
        return data.stream().map(InventoryReceiptVo::new).toList();
    }

    public String getTypeName() {
        if (type == null) {
            return null;
        }
        return type.label;
    }
}
